package com.swz.dcrm.adpter;



import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

/**
 * FragmentViewPagerAdapter
 */
public class FragmentViewPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;
    private List<String> titles;
    public FragmentViewPagerAdapter(FragmentManager manager, List<Fragment> fragments, List<String> titles) {
        super(manager);
        this.fragments = fragments;
        this.titles = titles;

    }
    @Override
    public Fragment getItem(int position) {

        return fragments.get(position);
    }
    @Override
    public int getCount() {
        return fragments.size();
    }
    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position,
                            Object object) {

    }
    @Override
    public int getItemPosition(@NonNull Object object) {
        // 取出设置的tag，返回位置信息
        View view = (View) object;
        String s= (String) view.getTag();
        if (s==null){
            s="0";
        }
        return Integer.valueOf(s);
    }
    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {

        return super.instantiateItem(container, position);
    }

    public void refreshTitles(List<String> titles) {
        this.titles = titles;
        notifyDataSetChanged();
    }
}
